//
// Created by 49647 on 2022/8/10.
//

#ifndef MEDIAMETA_MEDIAMETA_H
#define MEDIAMETA_MEDIAMETA_H

#include <string>
#include <any>
#include <unordered_map>
#include <typeinfo>

class MediaMeta {
public:
    template<typename T>
    void SetKV(const std::string &key, T &&value) {
        m_key2Value[key] = value;
        m_key2TypeName[key] = typeid(value).name();
        printf("key %s, valueType %s\n", key.c_str(), typeid(value).name());
    }

    void Print() {
        for (auto&[k, v] : m_key2Value) {
            std::string typeName = m_key2TypeName[k];
            if (typeName == typeid(int).name()) {
                printf("%s(int): %d\n", k.c_str(), std::any_cast<int>(v));
            } else if (typeName == typeid(std::string).name()) {
                printf("%s(string): %s\n", k.c_str(), std::any_cast<std::string>(v).c_str());
            } else {
                printf("%s(%s)\n", k.c_str(), typeName.c_str());
            }
        }
    }

private:
    std::unordered_map<std::string, std::any> m_key2Value;
    std::unordered_map<std::string, std::string> m_key2TypeName;
};


#endif //MEDIAMETA_MEDIAMETA_H
